jQuery("#price").on('blur',function(e){
	fixfloat(e,2);
	packOff();
});
jQuery('#amount').on('blur',function(e){
	packOff();
});
jQuery("#replacePrice").on('blur',function(e){
	fixfloat(e,2);
});

jQuery(".addOldERBtn").on('click',function(){
	var quoteId = jQuery("#id").val();
	if (quoteId == '') {
		if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		};
		saveQuote(5);
	}
	jQuery("#queryOtherHisModal").modal('show');
	serverOldDetailData.key = jQuery('#otherERHisDetailkeyword').val();
	serverOldDetailData.opid = -1;
	serverOldDetailTable.draw();
    jQuery("#HisDetailTable").resize();
});

jQuery(".searchHisDetailBtn").on("click",function(){
	serverOldDetailData.key = jQuery('#otherERHisDetailkeyword').val();
	serverOldDetailTable.draw();
    jQuery("#HisDetailTable").resize();
});

jQuery(".resetHisDetailBtn").on("click",function(){
	serverOldDetailData.key = "";
	jQuery('#otherERHisDetailkeyword').val("");
	serverOldDetailTable.draw();
    jQuery("#HisDetailTable").resize();
});

$('.insert-re').click(function() {
	var selects=getSelect("#otherTable",1);
	if(selects.length==1){
		showReplacementModal(selects[0].indexOrder);
	}else if(selects.length>1){
		message("选择一条数据，在此之前插入")
	}
});
$('.clearPrice').click(function() {
	var selects=getSelect("#otherTable",1);
	
	if(selects.length==0) return;
	
	
	var ids=selects[0].id;
	
	for(var i=1;i<selects.length;i++){
		ids+=","+selects[i].id;
	}
	var url=window.rootPath+'/ui/quote/clearPrice?ids='+ids;
	  jQuery.ajax({
         	type : 'get',
         	url : encodeURI(url),
         	dataType : 'json',
         	contentType : 'application/json;charset=utf-8',
         	success : function(data) {
         		serverTable1.draw();
         	}
         });    		
	
	
});

jQuery(".move").click(function(){
	var type=$(this).attr("data-toggle");
	var selects=getSelect("#otherTable",1);
	if(selects.length==1){
		var changeNum;
		if(type=="up"){
			changeNum=-1;
		}else{
			changeNum=1;
		}
		var id=selects[0].id;
		var indexOrder=selects[0].indexOrder;
		var quoteId=selects[0].quote.id;
		jQuery(".btn").attr("disabled",true);
		var url=window.rootPath+"/ui/quote/changeReplaceIndex?id="+id+"&oldIndexOrder="+indexOrder
		+"&changeNum="+changeNum+"&quoteId="+quoteId;
		 jQuery.ajax({
               	type : 'get',
               	url : encodeURI(url),
               	dataType : 'json',
               	contentType : 'application/json;charset=utf-8',
               	success : function(data) {
               		serverTable1.draw();
               		jQuery(".btn").attr("disabled",false);
               	}
               });
		
	}else if(selects.length>1){
		message("单条移动")
	}
	
});

jQuery(".choiceHisDetailBtn").on("click",function(){
	var selects = getSelect("#HisDetailTable", 1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		 var url=window.rootPath+"/ui/configdetailfor/saveOtherEROld"+"?ids="+ids+"&quoteId="+jQuery("#id").val();
		   $.springLemonDialog({
		         content: '确认选择'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(url),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	//serverData2.quoteId = jQuery("#id").val();
		        	            	serverTable.draw(false); 
		        	            	serverTable1.draw(); 
		        	            	//serverTable2.draw(); 
		        	            	productSum();
		        	            	jQuery(".btn").attr("disabled", false);
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
});

var serverOldDetailData = {};
serverOldDetailData.quoteid = -1;
var serverOldDetailTable;
jQuery(document).ready(function(){
	serverOldDetailTable = jQuery('#HisDetailTable').DataTable({
		"serverSide" : true,
		"ordering" : false,
        "scrollCollapse": true,
        "scrollY": "300px",
        "iDisplayLength" : 50,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getpagehisdetail',
			"data" : function(d) {
				return $.extend({}, d,serverOldDetailData);
					}
				},
					columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },{
			        	   data : null,
			        	   defaultContent : "",
			        	   render : function(data,type, full, meta) {
						      var id = data.id
							  var operate = '<input type="checkbox" class="checkchild">';
							  return operate;
								}
						},
			           {
							data : 'type'
						},
						{
							data : 'deviceName',
						},
						{
							data : 'material'
						},
						{
							data : 'amount'
						},
						{
							data : 'unit'
						},
						{
							data : 'costPrice'
						},
						{
							data : 'price'
						},
						{
							data: 'id'
						}
						],
			"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
							}
						}
					});
});

var otherERCRMContractData = {};
var otherERCRMContractTable;
jQuery(document).ready(function(){
	otherERCRMContractTable = jQuery('#otherERCRMContractTable').DataTable({
		"serverSide" : true,
		"ordering" : false,
        "scrollCollapse": true,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getproductplanpage',
			"data" : function(d) {
				return $.extend({}, d,otherERCRMContractData);
					}
				},
					columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },
			           {
							data : 'cContractNumber'
						},
						{
							data : 'cProductPlanNumber',
						},
						{
							data : 'cProductType'
						},
						{
							data : 'nCount'
						},
						{
							data : 'cOrderUnitName'
						},
						{
							data : 'dDeliverDate',
							render: function (data, type, full, meta) {
		                        if (data)
		                            return moment(data).format('YYYY/MM/DD');
		                        else
		                            return '';
		                    }
						},
						{
							data: 'id'
						}
						],
			"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
							}

						}
					});
					otherERCRMContractTable.off('dblclick', 'tr');
					otherERCRMContractTable.on('dblclick','tr',function(event) {
						 event = event|| window.event;
						 var target = event.target|| event.scrElement;
						 var data = otherERCRMContractTable.row(this).data();
						 var url2=window.rootPath+'/ui/configdetailfor/getconfigmainlist?opid='+data.id;
						 jQuery.ajax({
					          type: 'post',
					          url: encodeURI(url2),
					          dataType: 'json',
					          contentType: 'application/json;charset=utf-8',
					          success: function (databack) {
					        	     var maxIndex=jQuery("#ypzmc option:last").attr("index");
					        	     if(maxIndex >= 0){
					        	    	 for(var j=0;j<=maxIndex;j++){
					        	    		 jQuery("#ypzmc option[index='"+j+"']").remove();
					        	    	 }
					        	     }
					        	  	 if(databack.data.length > 0){
					        	  		 for(var i=0;i<databack.data.length;i++){
					        	  			$("#ypzmc").append("<option index='"+i+"' value='"+databack.data[i].cConfigurationType+"'>"+databack.data[i].cConfigurationType+"</option>");
					        	  		 }
					        	  	 }
									 serverotherERData.key = jQuery('#otherERkeyword').val();
									 serverotherERData.ntype = jQuery("#ypzmc").val();
								     serverotherERData.opid = data.id;
								     serverotherERTable.draw();
								     jQuery("#serverotherERTable").resize();
									 return;
					          }
			    	  	 });
					});
});

jQuery(".searchotherERCRMContractBtn").on("click",function(){
	 otherERCRMContractData.key = jQuery('#otherERCRMContractkeyword').val();
	 otherERCRMContractTable.draw();
	 jQuery("#otherERCRMContractTable").resize();
});

jQuery(".resetotherERCRMContractBtn").on("click",function(){
	 jQuery('#otherERCRMContractkeyword').val('');
	 otherERCRMContractData.key = '';
	 otherERCRMContractTable.draw();
	 jQuery("#otherERCRMContractTable").resize();
});

//添加二期配置弹窗
jQuery(".addOtherERBtn").on("click", function() {
	
	var selects=getSelect("#otherTable",1);
	if(selects.length==1){
		jQuery("#indexNumber").val(selects[0].indexOrder);
	}
	var quoteId = jQuery("#id").val();
	if (quoteId == '') {
		if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		};
		saveQuote(5);
	}
	jQuery("#queryOtherERModal").modal('show');
	serverotherERData.key = jQuery('#otherERkeyword').val();
    serverotherERData.opid = -1;
    serverotherERData.ntype = jQuery("#ypzmc").val();
    serverotherERTable.draw();
    jQuery("#serverotherERTable").resize();
});

jQuery(".searchotherERCRMHisBtn").on('click',function(){
	serverotherHisERData.key = jQuery('#otherERCRMHiskeyword').val();
	serverotherHisERTable.draw();
	 jQuery("#otherERCRMHisTable").resize();
});

jQuery(".resetotherERCRMHisBtn").on('click',function(){
	serverotherHisERData.key = "";
	jQuery('#otherERCRMHiskeyword').val("");
	serverotherHisERTable.draw();
	jQuery("#otherERCRMHisTable").resize();
});

var serverotherHisERData = {};
var serverotherHisERTable;
jQuery(document).ready(function(){
	serverotherHisERTable = jQuery('#otherERCRMHisTable').DataTable({
		"serverSide" : true,
		"ordering" : false,
        "scrollCollapse": true,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getpagehisquote',
			"data" : function(d) {
				return $.extend({}, d,serverotherHisERData);
					}
				},
					columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },
						{
							data : 'name'
						},
						{
							data : 'customerName'
						},
						{
							data : 'deliveryDate',
							render: function (data, type, full, meta) {
		                        if (data)
		                            return moment(data).format('YYYY/MM/DD');
		                        else
		                            return '';
		                    }
						},
						{
							data : 'costSum'
						},
						{
							data : 'sum'
						},
			           {
			        	   data : 'memo'
			           },{
			        	   data : 'id'
			           }],
			"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
							}

						}
					});
					 serverotherHisERTable.off('dblclick', 'tr');
					 serverotherHisERTable.on('dblclick','tr',function(event) {
					 event = event|| window.event;
					 var target = event.target|| event.scrElement;
					 var data = serverotherHisERTable.row(this).data();
					 serverOldDetailData.quoteid = data.id;
					 serverOldDetailData.key = jQuery('#otherERHisDetailkeyword').val();
					 serverOldDetailTable.draw();
				     jQuery("#HisDetailTable").resize();
					 return;
				});
});
var fatherPartId = -1;
var serverotherMFERData = {};
var serverotherMFERTable;
jQuery(document).ready(function(){
	serverotherMFERTable = jQuery('#otherMFERTable').DataTable({
		"serverSide" : true,
		"ordering" : false,
        "scrollCollapse": true,
        "scrollY": "300px",
        "iDisplayLength" : 50,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getpagemf',
			"data" : function(d) {
				return $.extend({}, d,serverotherMFERData);
					}
				},
					columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },{
			        	   data : null,
			        	   defaultContent : "",
			        	   render : function(data,type, full, meta) {
						      var id = data.id
							  var operate = '<input type="checkbox" class="checkchild">';
							  return operate;
								}
						},
						/*{
							data : 'cUpPartPicNum'
						},*/
						{
							data : 'cPartPicNum'
						},
						{
							data : 'cPartName'
						},
						{
							data : 'cMaterial'
						},
						{
							data : 'nCount'
						},
			           {
			        	   data : 'nBackCount'
			           },
			           {
			        	   data : 'cMemo'
			           }
						],
			"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
							}

						}
					});
					serverotherMFERTable.off('dblclick', 'tr');
					serverotherMFERTable.on('dblclick','tr',function(event) {
						 event = event|| window.event;
						 var target = event.target|| event.scrElement;
						 var data = serverotherMFERTable.row(this).data();
						 var url2=window.rootPath+'/ui/configdetailfor/getpagemfsecond?opid='+data.nPartId;
						 fatherPartId = data.nPartId;
						 jQuery.ajax({
					          type: 'post',
					          url: encodeURI(url2),
					          dataType: 'json',
					          contentType: 'application/json;charset=utf-8',
					          success: function (databack) {
					        	     var maxIndex=jQuery("#bjxx option:last").attr("index");
					        	     if(maxIndex >= 0){
					        	    	 for(var j=0;j<=maxIndex;j++){
					        	    		 jQuery("#bjxx option[index='"+j+"']").remove();
					        	    	 }
					        	     }
					        	  	 if(databack.data.length > 0){
					        	  		 for(var i=0;i<databack.data.length;i++){
					        	  			$("#bjxx").append("<option index='"+i+"' value='"+databack.data[i].nPartId+"'>"+databack.data[i].cPartPicNum+"</option>");
					        	  		 }
					        	  	 } 
					        	  	serverotherMFERData1.key = jQuery('#otherERkeyword1').val();
					        	  	serverotherMFERData1.ntype = jQuery("#bjxx").val() == "" ? -1 : jQuery("#bjxx").val();
					        	  	serverotherMFERData1.opid = fatherPartId;
					        	  	serverotherMFERTable1.draw();
								     jQuery("#otherMFERTable1").resize();
									 return;
					          }
					  	 });
					});
					
});

var serverotherMFERData1 = {};
var serverotherMFERTable1;
serverotherMFERData1.key = jQuery("#otherMFERkeyword1").val();
serverotherMFERData1.opid = fatherPartId;
serverotherMFERData1.ntype = jQuery("#bjxx").val() == "" ? -1 : jQuery("#bjxx").val();
jQuery(document).ready(function(){
	serverotherMFERTable1 = jQuery('#otherMFERTable1').DataTable({
		"serverSide" : true,
		"ordering" : false,
		"scrollCollapse": true,
		"scrollY": "300px",
		"iDisplayLength" : 50,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getpagemfdown',
			"data" : function(d) {
				return $.extend({}, d,serverotherMFERData1);
			}
		},
		columns : [
		           {
		        	   data : null,
		        	   defaultContent : "" 
		           },{
		        	   data : null,
		        	   defaultContent : "",
		        	   render : function(data,type, full, meta) {
		        		   var id = data.id
		        		   var operate = '<input type="checkbox" class="checkchild">';
		        		   return operate;
		        	   }
		           },
		           {
						data : 'cUpPartPicNum'
					},
		           {
		        	   data : 'cPartPicNum'
		           },
		           {
		        	   data : 'cPartName'
		           },
		           {
		        	   data : 'cMaterial'
		           },
		           {
		        	   data : 'nCount'
		           },
		           {
		        	   data : 'nBackCount'
		           },
		           {
		        	   data : 'cMemo'
		           }
		           ],
		           "drawCallback" : function(oSettings) {
		        	   var k = 0;
		        	   var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
		        	   for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		        		   $('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		        		   k++;
		        	   }
		        	   
		           }
	});
	
});


jQuery(".searchMFotherERBtn1").on('click',function(){
	 serverotherMFERData1.key = jQuery('#otherMFERkeyword1').val();
	 serverotherMFERData1.opid = fatherPartId;
	 serverotherMFERData1.ntype = jQuery("#bjxx").val() == "" ? -1 : jQuery("#bjxx").val();
	 serverotherMFERTable1.draw();
	 jQuery("#otherMFERTable1").resize();
});

jQuery(".resetMFotherERBtn1").on('click',function(){
	 serverotherMFERData1.key = "";
	 serverotherMFERData1.opid = fatherPartId;
	 serverotherMFERData1.ntype = jQuery("#bjxx").val() == "" ? -1 : jQuery("#bjxx").val();
	 jQuery('#otherMFERkeyword1').val("");
	 serverotherMFERTable1.draw();
	 jQuery("#otherMFERTable1").resize();
});

jQuery(".searchMFotherERBtn").on('click',function(){
	 serverotherMFERData.key = jQuery('#otherMFERkeyword').val();
	 serverotherMFERTable.draw();
	 jQuery("#otherMFERTable").resize();
});

jQuery(".resetMFotherERBtn").on('click',function(){
	 serverotherMFERData.key = "";
	 jQuery('#otherMFERkeyword').val("");
	 serverotherMFERTable.draw();
	 jQuery("#otherMFERTable").resize();
});

jQuery(".choiceMFBtn").on('click',function(){
	var selects = getSelect("#otherMFERTable", 1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		 var url=window.rootPath+"/ui/configdetailfor/saveOtherERMF"+"?ids="+ids+"&quoteId="+jQuery("#id").val();
		   $.springLemonDialog({
		         content: '确认选择'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(url),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	//serverData2.quoteId = jQuery("#id").val();
		        	            	serverTable.draw(false); 
		        	            	serverTable1.draw(); 
		        	            	//serverTable2.draw(); 
		        	            	productSum();
		        	            	jQuery(".btn").attr("disabled", false);
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
});
jQuery(".choiceMFBtn1").on('click',function(){
	var selects = getSelect("#otherMFERTable1", 1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		 var url=window.rootPath+"/ui/configdetailfor/saveOtherERMF"+"?ids="+ids+"&quoteId="+jQuery("#id").val();
		   $.springLemonDialog({
		         content: '确认选择'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(url),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	//serverData2.quoteId = jQuery("#id").val();
		        	            	serverTable.draw(false); 
		        	            	serverTable1.draw(); 
		        	            	//serverTable2.draw(); 
		        	            	productSum();
		        	            	jQuery(".btn").attr("disabled", false);
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
});

var serverotherERData = {};
serverotherERData.opid = -1;
serverotherERData.ntype = jQuery("#ypzmc").val();
var serverotherERTable;
jQuery(document).ready(function(){
	serverotherERTable = jQuery('#otherERTable').DataTable({
		"serverSide" : true,
		"ordering" : false,
        "scrollCollapse": true,
        "scrollY": "300px",
        "iDisplayLength" : 50,
		"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+ '/ui/configdetailfor/getpage',
			"data" : function(d) {
				return $.extend({}, d,serverotherERData);
					}
				},
					columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },{
			        	   data : null,
			        	   defaultContent : "",
			        	   render : function(data,type, full, meta) {
						      var id = data.id
							  var operate = '<input type="checkbox" class="checkchild">';
							  return operate;
								}
						},
						{
							data : 'cConfigurationType'
						},
						{
							data : 'cOrderNumber'
						},
						{
							data : 'cPartPicNumDes'
						},
						{
							data : 'cPartName'
						},
						{
							data : 'cMaterial'
						},
			           {
			        	   data : 'nTotalCount'
			           }
						],
			"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
							}

						}
					});
});

//var serverData2 = {};
//var serverTable2;
//serverData2.quoteId = jQuery("#id").val();
//jQuery(document).ready(function() {
//	serverTable2 = jQuery('#otherERCRMTable').DataTable({
//			"serverSide" : true,
//			"ordering" : false,
//			"ajax" : {
//			"dataType" : "json",
//			"type" : "get",
//			"cache" : false,
//			"url" : window.rootPath+'/ui/quote/getOtherpageER',
//			"data" : function(d) {
//					return $.extend({}, d,serverData2);
//									}
//					},
//			columns : [
//			           {
//			        	   data : null,
//						   defaultContent : "" 
//			           },
//			           {
//			        	   data : null,
//			        	   defaultContent : "",
//			        	   render : function(data,type, full, meta) {
//									var id = data.id
//									var operate = '<input type="checkbox" class="checkchild1">';
//									return operate;
//										}
//						}, 
//						{
//		                    data: 'deviceName',
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
//		                },
//		                {
//		                    data: 'type',
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
//		                },
//		                {
//		                	data: 'material',
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
//		                },
//		                {
//		                    data: 'unit'
//		                },
//		                {
//		                	data: 'amount'
//		                },
//		                {
//		                	data: 'costPrice'
//		                },
//		                {
//		                	data: 'price'
//		                }
//						],
//			"drawCallback" : function(oSettings) {
//						  var k = 0;
//						  var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
//						for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
//						    $('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
//									k++;
//										}
//									}
//								});
//					serverTable2.off('dblclick', 'tr');
//					serverTable2.on('dblclick','tr',function(event) {
//			    	event = event|| window.event;
//			    	var target = event.target|| event.scrElement;
//			    	var data = serverTable2.row(this).data();
//			    	jQuery('#ScadaRtuBaseInfoId').val(data.id);
//			    	ScadaRtuBaseInfoId = data.id;
//			    	jQuery("#otherId2").val(data.id);
//			 		 jQuery("#othercreateTime2").val(data.createTime);
//			 		 jQuery("#deviceName2").val(data.deviceName);
//			         jQuery("#type2").val(data.type);
//			         jQuery("#material2").val(data.material);
//			         jQuery("#unit2").val(data.unit);
//			         jQuery("#amount2").val(data.amount);
//			         jQuery("#price2").val(data.price);
//			         jQuery("#replacePrice2").val(data.costPrice);
//			         jQuery("#otherERDeviceModal").modal("show");
//			    	return;
//			    });
//			});

//添加二期配置弹窗
jQuery(".choiceBtn").on("click", function() {
	var indexOrder = jQuery("#indexNumber").val();
	var selects = getSelect("#otherERTable", 1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		 var url=window.rootPath+"/ui/configdetailfor/saveOtherER"+"?ids="+ids+"&quoteId="+jQuery("#id").val() + "&indexOrder=" + indexOrder;
		   $.springLemonDialog({
		         content: '确认选择'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(url),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	//serverData2.quoteId = jQuery("#id").val();
		        	            	serverTable.draw(false); 
		        	            	serverTable1.draw(); 
		        	            	//serverTable2.draw(); 
		        	            	productSum();
		        	            	jQuery("#indexNumber").val("");
		        	            	jQuery(".btn").attr("disabled", false);
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
});


////二期上查询
jQuery('.searchotherERBtn').on('click', function() {
	 serverotherERData.key = jQuery('#otherERkeyword').val();
	 serverotherERData.ntype = jQuery("#ypzmc").val();
	 serverotherERTable.draw();
	 jQuery("#serverotherERTable").resize();
})
jQuery('.resetotherERBtn').on("click", function() {
	 jQuery('#otherERkeyword').val('');
	 serverotherERData.key = '';
	 serverotherERData.ntype = '';
	 serverotherERTable.draw();
	 jQuery("serverotherERTable").resize();
});

////二期下查询
jQuery('.searchotherERCRMBtn').on('click', function() {
	 serverData2.key = jQuery('#otherERCRMkeyword').val();
	 serverTable1.draw();
	 //serverTable2.draw();
})
jQuery('.resetotherERCRMBtn').on("click", function() {
	 jQuery('#otherERCRMkeyword').val('');
	 serverData2.key = '';
	 serverTable1.draw();
	 //serverTable2.draw();
});
jQuery('.editotherERCRMBtn').on("click", function() {
	var selects = getSelect("#otherERCRMTable", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : '一次只能编辑一条记录',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
	} else if (selects.length == 0) {
		$.springLemonDialog({
			content : '请选择要编辑的记录',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
	} else if (selects.length == 1) {
		 var id=selects[0].id;
	 	    jQuery("#otherId2").val(id);
 		 jQuery("#othercreateTime2").val(selects[0].createTime);
 		 jQuery("#deviceName2").val(selects[0].deviceName);
         jQuery("#type2").val(selects[0].type);
         jQuery("#material2").val(selects[0].material);
         jQuery("#unit2").val(selects[0].unit);
         jQuery("#amount2").val(selects[0].amount);
         jQuery("#price2").val(selects[0].price);
         jQuery("#replacePrice2").val(selects[0].costPrice);
         jQuery("#otherERDeviceModal").modal("show");
	}
});

jQuery(".addMFERBtn").on('click',function(){
	var quoteId = jQuery("#id").val();
	if (quoteId == '') {
		if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		};
		saveQuote(5);
	}
	jQuery("#queryOtherMFERModal").modal('show');
	fatherPartId = -1;
	serverotherMFERData1.key = jQuery('#otherERkeyword1').val();
  	serverotherMFERData1.ntype = -1;
  	serverotherMFERData1.opid = -1;
  	serverotherMFERTable1.draw();
     jQuery("#otherMFERTable1").resize();
});

jQuery('.saveOtherERBtn').on("click", function() {
		var url2=window.rootPath+'/ui/quote/saveOtherDevice';
		var quoteId = jQuery("#id").val();
		var otherId = jQuery("#otherId2").val();
		var deviceName = jQuery("#deviceName2").val();
		var type = jQuery("#type2").val();
		var material = jQuery("#material2").val();
		var unit = jQuery("#unit2").val();
		var amount = jQuery("#amount2").val();
		var price = jQuery("#price2").val();
		var replacePrice = jQuery("#replacePrice2").val();
		var createTime=jQuery("#othercreateTime2").val();
		
		var d = {
			    "id":otherId,
			    "createTime":createTime,
			    "deviceName": deviceName,
                "type": type,
                "material": material,
                "unit": unit,
                "amount": amount,
                "price": price,
                "costPrice": replacePrice,
   	            "quote": {
   	                "id": quoteId
   	            } 
   	        };
		jQuery(".btn").attr("disabled", true);
		jQuery.ajax({
	          type: 'post',
	          url: encodeURI(url2),
	          data: JSON.stringify(d),
	          dataType: 'json',
	          contentType: 'application/json;charset=utf-8',
	          success: function (data) {
	        	  	productSum();
	        	  	serverTable1.draw();
	        	  	//serverTable2.draw();
	        		jQuery('#otherERDeviceModal').modal('hide');
	        		jQuery(".btn").attr("disabled", false);
	          }
    	  	});
});

jQuery('.delotherERCRMBtn').on("click", function() {
	var selects=getSelect("#otherERCRMTable",1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择删除的记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		 var url=window.rootPath+"/ui/quote/delOtherDevice"+"?ids="+ids;
		   $.springLemonDialog({
		         content: '确认删除'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(url),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	serverTable1.draw(false); 
		        	            	//serverTable2.draw(false); 
		        	            	productSum();
		        	            	jQuery(".btn").attr("disabled", false);
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
});

jQuery('.searchotherERCRM2Btn').on("click", function() {
	var selects=getSelect("#otherERCRMTable",1);
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择查询数据',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else if(selects.length>1){
		   $.springLemonDialog({
		         content: '只能查询一条数据',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		       }); 
	   }else {
		 //var url=window.rootPath+"/ui/quote/delOtherDevice"+"?ids="+ids;
		 //jQuery("#typekeyword").val(selects[0].type);
		   var id=selects[0].id;
		   jQuery("#otherId1").val(id);
	 		 jQuery("#othercreateTime1").val(selects[0].createTime);
	 		 jQuery("#deviceName1").val(selects[0].deviceName);
	         jQuery("#type1").val(selects[0].type);
	         jQuery("#material1").val(selects[0].material);
	         jQuery("#unit1").val(selects[0].unit);
	         jQuery("#amount1").val(selects[0].amount);
	         jQuery("#price1").val(selects[0].price);
	         jQuery("#replacePrice1").val(selects[0].costPrice);
         jQuery("#customerNamekeyword").val(selects[0].quote.customerName);
         serverData3.customerName = selects[0].quote.customerName;
		 jQuery("#typekeyword").val(selects[0].type);
		 serverData3.type = selects[0].type;
		 jQuery("#deviceNamekeyword").val(selects[0].deviceName);
		 serverData3.deviceName = selects[0].deviceName;
		 jQuery("#materialkeyword").val(selects[0].material);
		 serverData3.material = selects[0].material;
		 serverTable3.draw();
		 jQuery("#queryOtherERPriceModal").modal("show");
	   }
});
jQuery('#pull-in-otherreplacePrice').on("click", function() {
	var selects=getSelect("#otherreplacePriceTable",1);
	if(selects.length==0){
		$.springLemonDialog({
			content: '请选择要引入的数据',// 确认文本
			clickButton: function (sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		}); 
	}else if(selects.length>1){
		$.springLemonDialog({
			content: '只能选择一条数据',// 确认文本
			clickButton: function (sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		}); 
	}else if(selects.length==1){
		jQuery("#customerNamekeyword").val("");
		jQuery("#typekeyword").val("");
		jQuery("#deviceNamekeyword").val("");
		jQuery("#materialkeyword").val("");
		
		var url2=window.rootPath+'/ui/quote/saveOtherDevice';
		var quoteId = jQuery("#id").val();
		var otherId = jQuery("#otherId1").val();
		var deviceName = jQuery("#deviceName1").val();
		var type = jQuery("#type1").val();
		var material = jQuery("#material1").val();
		var unit = jQuery("#unit1").val();
		var amount = jQuery("#amount1").val();
		var price = selects[0].price;
		var replacePrice = selects[0].costPrice;
		var createTime=jQuery("#othercreateTime1").val();
		
		var d = {
			    "id":otherId,
			    "createTime":createTime,
			    "deviceName": deviceName,
                "type": type,
                "material": material,
                "unit": unit,
                "amount": amount,
                "price": price,
                "costPrice": replacePrice,
   	            "quote": {
   	                "id": quoteId
   	            } 
   	        };
		jQuery(".btn").attr("disabled", true);
		jQuery.ajax({
	          type: 'post',
	          url: encodeURI(url2),
	          data: JSON.stringify(d),
	          dataType: 'json',
	          contentType: 'application/json;charset=utf-8',
	          success: function (data) {
	        	  	productSum();
	        	  	serverTable1.draw();
	        	  	//serverTable2.draw();
	        		jQuery('#queryOtherERPriceModal').modal('hide');
	        		jQuery(".btn").attr("disabled", false);
	          }
    	  	});
	}
});

var serverData3 = {};
var serverTable3;
jQuery(document).ready(function() {
	serverTable3 = jQuery('#otherreplacePriceTable').DataTable({
			"serverSide" : true,
			"ordering" : false,
			"ajax" : {
			"dataType" : "json",
			"type" : "get",
			"cache" : false,
			"url" : window.rootPath+'/ui/quote/getOtherpageprice',
			"data" : function(d) {
					return $.extend({}, d,serverData3);
									}
					},
			columns : [
			           {
			        	   data : null,
						   defaultContent : "" 
			           },
			           {
			        	   data : null,
			        	   defaultContent : "",
			        	   render : function(data,type, full, meta) {
									var id = data.id
									var operate = '<input type="checkbox" class="checkchild1">';
									return operate;
										}
						}, 
						{
							data: 'quote.customerName'
						},
						{
		                    data: 'deviceName'
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
		                },
		                {
		                    data: 'type'
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
		                },
		                {
		                	data: 'material'
//							render:function(data,type,full,meta){
//								return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//								//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//							}
		                },
		                {
		                    data: 'unit'
		                },
		                {
		                	data: 'amount'
		                },
		                {
		                	data: 'costPrice'
		                },
		                {
		                	data: 'price'
		                }
						],
			"drawCallback" : function(oSettings) {
						  var k = 0;
						  var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
						for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						    $('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
									k++;
										}
									}
								});

			});

////二期下查询
jQuery('.searchReplacePriceBtn').on('click', function() {
	 serverData3.type = jQuery("#typekeyword").val();
	 serverData3.deviceName = jQuery("#deviceNamekeyword").val();
	 serverData3.material = jQuery("#materialkeyword").val();
	 serverTable3.draw();
})
/*jQuery('.resetotherERCRMBtn').on("click", function() {
	 jQuery('#otherERCRMkeyword').val('');
	 serverData2.key = '';
	 serverTable1.draw();
	 serverTable2.draw();
});*/


	jQuery(document).ready(function(){
		// 引入客户信息弹窗
		jQuery('#queryCustomer').on("click", function() {
			showCustomer();// 显示客户信息
		});
		jQuery('#pull-customer-in').click(function(){
			var selects = getSelect("#query-customer-table", 1);
			//console.log("111")
			if (selects.length > 1) {
				message("只能引入一条客户");
			} else if (selects.length == 0) {
				message("没有选中客户");
			} else if (selects.length == 1) {
				jQuery("#customerId").val(selects[0].id);
				jQuery("#customerName").val(selects[0].customerName);
				jQuery("#query-Customer-Modal").modal('hide');
			}
		});
	});
	
	////获附件数量
	var quoteId=jQuery("#id").val();
	var numId='quoteANum';
	if(quoteId!=''){
		showANum(quoteId,'普通价格单附件',numId);
	}
	
	
	
 ////////////////////////   泵             /////////////////////
   // 泵table
		var serverData = {};
		serverData.quoteId = jQuery("#id").val();
		var serverTable;
		jQuery(document).ready(function() {
				serverTable = jQuery('#mainDeviceTable').DataTable({
						"serverSide" : true,
						"ordering" : false,
						"ajax" : {
							"dataType" : "json",
							"type" : "get",
							"cache" : false,
							"url" : window.rootPath+ '/ui/quote/getDevicepage',
							"data" : function(d) {
								return $.extend({}, d,serverData);
									}
								},
							columns : [
							           {
							        	   data:null,
							        	   defaultContent : "" 
							           },
								       {
							        	   data : null,
							        	   defaultContent : "",
							        	   render : function(data,type, full, meta) {
										      var id = data.id
											  var operate = '<input type="checkbox" class="checkchild">';
											  return operate;
												}
										},
										{
											data : 'productName'
//											render:function(data,type,full,meta){
//												return '<font title="'+data+'">'+data.substring(0,20)+'...'+'</font>';
//												//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//											}
										},
										{
											data : 'productType'
//											render:function(data,type,full,meta){
//												return '<font title="'+data+'">'+data.substring(0,20)+'...'+'</font>';
//												//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//											}
										},
										{
											data : 'productModel'
//											render:function(data,type,full,meta){
//												return '<font title="'+data+'">'+data.substring(0,20)+'...'+'</font>';
//												//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//											}
										},
										{
											data : null,
											render : function(data,type, full, meta) {
												var dOut;
												if (data.isInventory == "1") {
													dOut = '<td class="center" ><span class="badge label-pill label-primary">降库产品</span></td>';
												} else if (data.isInventory == "2"){
													dOut = '<td class="center" ><span class="badge label-pill label-success">被降库</span></td>';
												}else{
													dOut = '<td class="center" ><span class="badge label-pill label-danger">未降库</span></td>';
												}
												return dOut;
													}
										},
										{
											data : 'number'
										},
										{
											data:	'unit'
										},
										{
											data : 'costPrice'
										},
										{
											data : 'unitPrice'
										}, 
										{
											data : 'power'
										}, 
										{
											data : 'flowMaterial'
										},
										{
											data : 'transMedia'
										},
										{
											data : 'viscosity'
										},
										{
											data : 'flux'
										}, 
										{
											data : 'pumpLift'
										}, 
										{
											data : 'temperature'
										}, 
										{
											data : 'proportion'
										}, 
										{
											data : 'inPressure'
										}, 
										{
											data : 'effectiveNPSHA'
										}, 
										{
											data : 'mustMPSHA'
										}
										],
							"drawCallback" : function(oSettings) {
									var k = 0;
									var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
									for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
										$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
												k++;
											}

										}
									});
				});
		
		// 泵 添加按钮
		jQuery('.addMainBtn').on("click", function() {
			if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
				return;
			}
			;
			jQuery("#mainDeviceId").val('');
			jQuery("#productName").val('');
			jQuery("#productType").val('');
			jQuery("#productModel").val('');
			jQuery("#number").val('');
			jQuery("#unitPrice").val('');
			jQuery("#costPrice").val('');
			jQuery("#power").val('');
			jQuery("#viscosity").val('');
			jQuery("#flowMaterial").val('');
			jQuery("#transMedia").val('');
			jQuery("#proportion").val('');
			jQuery("#NPSHA").val('');
			jQuery("#flux").val('');
			jQuery("#temperature").val('');
			jQuery("#MPSHA").val('');
			jQuery("#pumpLift").val('');
			jQuery("#inPressure").val('');
			nowData.nowDataId = '';
			inDeviceData.quoteDeviceId = '';
			nowDataTable.draw();
			inDeviceTable.draw();
			jQuery("#mainDeviceModal").modal('show');
		});

	// 编辑泵
	jQuery(".editMainBtn").on('click', function() {
		var selects = getSelect("#mainDeviceTable", 1);
		if (selects.length > 1) {
			$.springLemonDialog({
				content : '一次只能编辑一条记录',// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		} else if (selects.length == 0) {
			$.springLemonDialog({
				content : '请选择要编辑的记录',// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		} else if (selects.length == 1) {
			if(selects[0].linkDeviceId==null){
			var id = selects[0].id;
			nowData.nowDataId = id;
			inDeviceData.quoteDeviceId = id;
			nowDataTable.draw();
			inDeviceTable.draw();
			jQuery("#mainDeviceId").val(id);
			jQuery("#maincreateTime").val(selects[0].createTime);
			jQuery("#productName").val(selects[0].productName);
			jQuery("#productType").val(selects[0].productType);
			jQuery("#productModel").val(selects[0].productModel);
			jQuery("#number").val(selects[0].number);
			jQuery("#quoteDeviceUnit").val(selects[0].unit);
			jQuery("#unitPrice").val(selects[0].unitPrice);
			jQuery("#costPrice").val(selects[0].costPrice);
			jQuery("#power").val(selects[0].power);
			jQuery("#viscosity").val(selects[0].viscosity);
			jQuery("#flowMaterial").val(selects[0].flowMaterial);
			jQuery("#transMedia").val(selects[0].transMedia);
			jQuery("#proportion").val(selects[0].proportion);
			jQuery("#NPSHA").val(selects[0].effectiveNPSHA);
			jQuery("#flux").val(selects[0].flux);
			jQuery("#temperature").val(selects[0].temperature);
			jQuery("#MPSHA").val(selects[0].mustMPSHA);
			jQuery("#pumpLift").val(selects[0].pumpLift);
			jQuery("#inPressure").val(selects[0].inPressure);
			jQuery("#inventoryState").val(selects[0].inventoryState);
			}
			else{
				var url=window.rootPath+'/ui/quote/getEditQuoteDevice'+"?quoteDeviceId="+selects[0].linkDeviceId;
				jQuery.ajax({
			          type: 'get',
			          url: encodeURI(url),
			          dataType: 'json',
			          contentType: 'application/json;charset=utf-8',
			          success: function (data) { 
			        	  var id=data.quoteDevice.id;
			        	    nowData.nowDataId = id;
							inDeviceData.quoteDeviceId = id;
							nowDataTable.draw();
							inDeviceTable.draw();
							jQuery("#mainDeviceId").val(id);
							jQuery("#maincreateTime").val(data.quoteDevice.createTime);
							jQuery("#productName").val(data.quoteDevice.productName);
							jQuery("#productType").val(data.quoteDevice.productType);
							jQuery("#productModel").val(data.quoteDevice.productModel);
							jQuery("#number").val(data.quoteDevice.number);
							jQuery("#quoteDeviceUnit").val(data.quoteDevice.unit);
							jQuery("#unitPrice").val(data.quoteDevice.unitPrice);
							jQuery("#costPrice").val(data.quoteDevice.costPrice);
							jQuery("#power").val(data.quoteDevice.power);
							jQuery("#viscosity").val(data.quoteDevice.viscosity);
							jQuery("#flowMaterial").val(data.quoteDevice.flowMaterial);
							jQuery("#transMedia").val(data.quoteDevice.transMedia);
							jQuery("#proportion").val(data.quoteDevice.proportion);
							jQuery("#NPSHA").val(data.quoteDevice.effectiveNPSHA);
							jQuery("#flux").val(data.quoteDevice.flux);
							jQuery("#temperature").val(data.quoteDevice.temperature);
							jQuery("#MPSHA").val(data.quoteDevice.mustMPSHA);
							jQuery("#pumpLift").val(data.quoteDevice.pumpLift);
							jQuery("#inPressure").val(data.quoteDevice.inPressure);
							jQuery("#inventoryState").val(data.quoteDevice.inventoryState);
			          }
			  	  	});
			}
			jQuery("#startDate").val('');
			jQuery("#endDate").val('');
			jQuery("#reduceNumber").val('');
			jQuery("#mainDeviceModal").modal('show');
		}

	});
	// 删除泵
	jQuery(".delMainBtn").on('click', function() {
   	 var selects=getSelect("#mainDeviceTable",1);
 		if(selects.length==0){
 		       $.springLemonDialog({
 		         content: '请选择删除的记录',// 确认文本
 		         clickButton: function (sender, modal, index) {// 按钮事件处理
 		             $(this).closeDialog(modal);
 		         }
 		       }); 
 		   }else{
 			   var ids=selects[0].id;
 			   for(var i=1;i<selects.length;i++){
 				   ids += ',' + selects[i].id;  
 			   }
 			 var url=window.rootPath+"/ui/quote/delMainDevice"+"?ids="+ids;
 			   $.springLemonDialog({
 			         content: '确认删除'+selects.length+'条记录？',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			        	 if (index == 0) {
 			        		jQuery(".btn").attr("disabled", true);
 			        		 jQuery.ajax({
 			        			    url:encodeURI(url),
 			        	            cache:false,
 			        	            type :"get",
 			        	            dataType:"json",
 			        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
 			        	            success:function(data){
 			        	            	serverTable.draw(false); 
 			        	            	productSum();
 			        	            	jQuery(".btn").attr("disabled", false);
 			        	            }
 			        	        });	
 			        	 }
 			             $(this).closeDialog(modal);
 			         }
 			       });  
 		   }
	});

	// 泵保存按钮
	jQuery(".saveMainBtn").on("click", function() {
		if (jQuery("#mainDeviceForm") && !jQuery("#mainDeviceForm").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		}
		var quoteId = jQuery("#id").val();
		if (quoteId == '') {
			$.springLemonDialog({
				content : '将会同时保存价格单，是否确认保存？',// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					if (index == 0) {
						saveQuote(2);
					}
					$(this).closeDialog(modal);
				}
			});
		} else if (quoteId != '') {
			savePump(quoteId);
		}
	});
   ///////////////////////////    其他       ///////////////////////////////
	// 其他table
	var serverData1 = {};
	var serverTable1;
	serverData1.quoteId = jQuery("#id").val();
	jQuery(document).ready(function() {
		
		/*jQuery('#amount').blur(function() {
			packOff();
		});
		jQuery('#price').blur(function() {
			packOff();
		});*/
		
		
		serverTable1 = jQuery('#otherTable').DataTable({
				"serverSide" : true,
				"ordering" : false,
				"scrollY": "600px",
		        "iDisplayLength" : 50,
				"ajax" : {
				"dataType" : "json",
				"type" : "get",
				"cache" : false,
				"length" : -1,
				"url" : window.rootPath+'/ui/quote/getOtherpage',
				"data" : function(d) {
						return $.extend({}, d,serverData1);
										}
						},
				columns : [
				           {
				        	   data : "indexOrder"
				           },
				           {
				        	   data : null,
				        	   defaultContent : "",
				        	   render : function(data,type, full, meta) {
										var id = data.id
										var operate = '<input type="checkbox" class="checkchild1">';
										return operate;
											}
							}, 
							{
			                    data: 'deviceName'
//								render:function(data,type,full,meta){
//									return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//								}
			                },
			                {
			                    data: 'type'
//								render:function(data,type,full,meta){
//									return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//								}
			                },
			                {
			                	data: 'material'
//								render:function(data,type,full,meta){
//									return '<font title="'+data+'">'+data.substring(0,30)+'...'+'</font>';
//									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
//								}
			                },
			                {
			                    data: 'unit'
			                },
			                {
			                	data: 'amount'
			                },
			                {
			                	data: 'costPrice'
			                },
			                {
			                	data: 'price'
			                },
			                {
			                	data: 'discount'
			                },
			                {
			                	data: 'materialCoding'
			                },
			                {
			                	data: 'cusMaterielSpec'
			                },
			                {
			                	data: 'cusMaterielName'
			                },
			                {
			                	data: 'branchFactory'
			                },
			                {
			                	data: 'memo'
			                }
							],
				"drawCallback" : function(oSettings) {
//							  var k = 0;
//							  var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
//							for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
//							    $('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
//										k++;
//											}
										}
									});
//		serverTable1.off('dblclick', 'tr');
//		serverTable1.on('dblclick','tr',function(event) {
//    	event = event|| window.event;
//    	var target = event.target|| event.scrElement;
//    	var data = serverTable1.row(this).data();
//    	 jQuery("#otherId").val(data.id);
// 		 jQuery("#othercreateTime").val(data.createTime);
// 		 jQuery("#deviceName").val(data.deviceName);
//         jQuery("#type").val(data.type);
//         jQuery("#material").val(data.material);
//         jQuery("#unit").val(data.unit);
//         jQuery("#amount").val(data.amount);
//         jQuery("#price").val(data.price);
//         jQuery("#replacePrice").val(data.costPrice);
//         jQuery("#indexOrder").val(data.indexOrder);
//         jQuery("#nowIndex_").val(jQuery('#otherTable').DataTable().context[0]._iRecordsTotal);
//	     jQuery("#pageIndex_").val(jQuery('#otherTable').DataTable().page.info().recordsTotal + 1);
//	     var htmltemp = jQuery("#nowIndex_").val() + "/" + jQuery("#pageIndex_").val() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
//	     $("#indexofpage_").html(htmltemp);
//         jQuery("#otherDeviceModal").modal("show");
//    	 return;
//		});

				});

// 其他 添加按钮
		jQuery(".addOtherBtn").on('click', function() {
			if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
				return;
			}
			showReplacementModal();
		});
		var showReplacementModal = function(order) {
			if(order){
        		jQuery('#indexOrder').val(order);
        		jQuery("#nowIndex_").val(order);
        		jQuery("#pageIndex_").val(jQuery('#otherTable').DataTable().page.info().recordsTotal + 1);
        	}else{
        		jQuery('#indexOrder').val(jQuery('#otherTable').DataTable().context[0]._iRecordsTotal + 1);
        		jQuery("#nowIndex_").val(jQuery('#otherTable').DataTable().page.info().recordsTotal + 1);
        		jQuery("#pageIndex_").val(jQuery('#otherTable').DataTable().page.info().recordsTotal + 1);
        	}
			
			jQuery("#otherId").val('');
			jQuery("#deviceName").val('');
		    jQuery("#type").val('');
		    jQuery("#material").val('');
		    jQuery("#amount").val('');
		    jQuery("#price").val('');
		    jQuery("#replacePrice").val('');
		    jQuery("#otherdiscount").val('');
	         jQuery("#materialCoding").val('');
	         jQuery("#cusMaterielSpec").val('');
	         jQuery("#cusMaterielName").val('');
	         jQuery("#branchFactory").val('');
	         jQuery("#othermemo").val('');
		    
		    var htmltemp = jQuery("#nowIndex_").val() + "/" + jQuery("#pageIndex_").val() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		    $("#indexofpage_").html(htmltemp);
			jQuery("#otherDeviceModal").modal("show");
		};
// 其他编辑
jQuery(".editOtherBtn").on('click', function() {
	var selects = getSelect("#otherTable", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : '一次只能编辑一条记录',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
	} else if (selects.length == 0) {
		$.springLemonDialog({
			content : '请选择要编辑的记录',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
	} else if (selects.length == 1) {
		 var id=selects[0].id;
	 	    jQuery("#otherId").val(id);
 		 jQuery("#othercreateTime").val(selects[0].createTime);
 		 jQuery("#deviceName").val(selects[0].deviceName);
         jQuery("#type").val(selects[0].type);
         jQuery("#material").val(selects[0].material);
         jQuery("#unit").val(selects[0].unit);
         jQuery("#amount").val(selects[0].amount);
         jQuery("#price").val(selects[0].price);
         jQuery("#replacePrice").val(selects[0].costPrice);
         jQuery("#indexOrder").val(selects[0].indexOrder);
         jQuery("#otherdiscount").val(selects[0].discount);
         jQuery("#materialCoding").val(selects[0].materialCoding);
         jQuery("#cusMaterielSpec").val(selects[0].cusMaterielSpec);
         jQuery("#cusMaterielName").val(selects[0].cusMaterielName);
         jQuery("#branchFactory").val(selects[0].branchFactory);
         jQuery("#othermemo").val(selects[0].memo);
         
         jQuery("#nowIndex_").val(selects[0].indexOrder);
	     jQuery("#pageIndex_").val(jQuery('#otherTable').DataTable().page.info().recordsTotal);
	     var htmltemp = jQuery("#nowIndex_").val() + "/" + jQuery("#pageIndex_").val() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	     $("#indexofpage_").html(htmltemp);
         jQuery("#otherDeviceModal").modal("show");
	}
});


jQuery(".beforeDataBtn").on('click',function(){
	var quoteId = jQuery("#id").val();
	if (jQuery("#otherDeviceForm") && !jQuery("#otherDeviceForm").Validform({
		tiptype : 3,
		showAllError : true
	}).check(false)) {
		return;
	}
	if (quoteId == '') {
		$.springLemonDialog({
			content : '将会同时保存价格单，是否确认保存？',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				if (index == 0) {
					saveQuote(3);
				}
				$(this).closeDialog(modal);
			}
		});
	} else if (quoteId != '') {
		var indexOrder = jQuery('#indexOrder').val();
		saveOther(quoteId);
		productSum();
		getNextOrBeforeData(quoteId,indexOrder,0,jQuery("#pageIndex_").val());
		/*var url2=window.rootPath+'/ui/quote/saveOtherDevice';
	    var otherId = jQuery("#otherId").val();
		var deviceName = jQuery('#deviceName').val();
		var type = jQuery('#type').val();
		var material = jQuery("#material").val();
		var unit = jQuery('#unit').val();
		var amount = jQuery('#amount').val();
		var price = jQuery('#price').val();
		var replacePrice = jQuery('#replacePrice').val();
		var indexOrder = jQuery('#indexOrder').val();
		if(otherId==''){
			var d = {
			 	"id":otherId,
                "deviceName": deviceName,
                "type": type,
                "material": material,
                "unit": unit,
                "amount": amount,
                "price": price,
                "costPrice": replacePrice,
                "indexOrder" : indexOrder,
   	            "quote": {
   	                "id": quoteId
   	            } 
   	        };
	   }else{
		var createTime=jQuery("#othercreateTime").val();
		 var d = {
				    "id":otherId,
				    "createTime":createTime,
				    "deviceName": deviceName,
                    "type": type,
                    "material": material,
                    "unit": unit,
                    "amount": amount,
                    "price": price,
                    "costPrice": replacePrice,
                    "indexOrder" : indexOrder,
	   	            "quote": {
	   	                "id": quoteId
	   	            } 
	   	        };
	   }
		jQuery(".btn").attr("disabled", true);
  	  	jQuery.ajax({
          type: 'post',
          url: encodeURI(url2),
          data: JSON.stringify(d),
          dataType: 'json',
          contentType: 'application/json;charset=utf-8',
          success: function (data) {
        	  	productSum();
        	  	serverTable1.draw();
        	  	//serverTable2.draw();
        		jQuery(".btn").attr("disabled", false);
        		getNextOrBeforeData(quoteId,indexOrder,0,jQuery("#pageIndex_").val());
          }
  	  	});*/
	}
});

jQuery(".nextDataBtn").on('click',function(){
	var quoteId = jQuery("#id").val();
	if (jQuery("#otherDeviceForm") && !jQuery("#otherDeviceForm").Validform({
		tiptype : 3,
		showAllError : true
	}).check(false)) {
		return;
	}
	if (quoteId == '') {
		$.springLemonDialog({
			content : '将会同时保存价格单，是否确认保存？',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				if (index == 0) {
					saveQuote(3);
				}
				$(this).closeDialog(modal);
			}
		});
	} else if (quoteId != '') {
		var indexOrder = jQuery('#indexOrder').val();
		saveOther(quoteId);
		productSum();
		getNextOrBeforeData(quoteId,indexOrder,1,jQuery("#pageIndex_").val());
		/*var url2=window.rootPath+'/ui/quote/saveOtherDevice';
	    var otherId = jQuery("#otherId").val();
		var deviceName = jQuery('#deviceName').val();
		var type = jQuery('#type').val();
		var material = jQuery("#material").val();
		var unit = jQuery('#unit').val();
		var amount = jQuery('#amount').val();
		var price = jQuery('#price').val();
		var replacePrice = jQuery('#replacePrice').val();
		var indexOrder = jQuery('#indexOrder').val();
		if(otherId==''){
			var d = {
			 	"id":otherId,
                "deviceName": deviceName,
                "type": type,
                "material": material,
                "unit": unit,
                "amount": amount,
                "price": price,
                "costPrice": replacePrice,
                "indexOrder" : indexOrder,
   	            "quote": {
   	                "id": quoteId
   	            } 
   	        };
	   }else{
		var createTime=jQuery("#othercreateTime").val();
		 var d = {
				    "id":otherId,
				    "createTime":createTime,
				    "deviceName": deviceName,
                    "type": type,
                    "material": material,
                    "unit": unit,
                    "amount": amount,
                    "price": price,
                    "costPrice": replacePrice,
                    "indexOrder" : indexOrder,
	   	            "quote": {
	   	                "id": quoteId
	   	            } 
	   	        };
	   }
		jQuery(".btn").attr("disabled", true);
  	  	jQuery.ajax({
          type: 'post',
          url: encodeURI(url2),
          data: JSON.stringify(d),
          dataType: 'json',
          contentType: 'application/json;charset=utf-8',
          success: function (data) {
        	  	productSum();
        	  	serverTable1.draw();
        	  	//serverTable2.draw();
        		jQuery(".btn").attr("disabled", false);
        		getNextOrBeforeData(quoteId,indexOrder,1,jQuery("#pageIndex_").val());
          }
  	  	});*/
	}
});

//其他删除
jQuery(".delOtherBtn").on('click',function(){
	 var selects=getSelect("#otherTable",1);
		if(selects.length==0){
		       $.springLemonDialog({
		         content: '请选择删除的记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		       }); 
		   }else{
			   var ids=selects[0].id;
			   for(var i=1;i<selects.length;i++){
				   ids += ',' + selects[i].id;  
			   }
			 var url=window.rootPath+"/ui/quote/delOtherDevice"+"?ids="+ids;
			   $.springLemonDialog({
			         content: '确认删除'+selects.length+'条记录？',// 确认文本
			         clickButton: function (sender, modal, index) {// 按钮事件处理
			        	 if (index == 0) {
			        		jQuery(".btn").attr("disabled", true);
			        		 jQuery.ajax({
			        			    url:encodeURI(url),
			        	            cache:false,
			        	            type :"get",
			        	            dataType:"json",
			        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
			        	            success:function(data){
			        	            	serverTable1.draw(false); 
			        	            	//serverTable2.draw(false); 
			        	            	productSum();
			        	            	jQuery(".btn").attr("disabled", false);
			        	            }
			        	        });	
			        	 }
			             $(this).closeDialog(modal);
			         }
			       });  
		   }
});

// 其他保存按钮
jQuery(".saveOtherBtn").on("click", function() {
	var quoteId = jQuery("#id").val();
	if (jQuery("#otherDeviceForm") && !jQuery("#otherDeviceForm").Validform({
		tiptype : 3,
		showAllError : true
	}).check(false)) {
		return;
	}
	if (quoteId == '') {
		$.springLemonDialog({
			content : '将会同时保存价格单，是否确认保存？',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				if (index == 0) {
					saveQuote(3);
				}
				$(this).closeDialog(modal);
			}
		});
	} else if (quoteId != '') {
		saveOther(quoteId);
	}
});


 /////////////////////// /   泵添加弹窗中table   //////////////////////////
	// 弹窗中当前设备信息Table
	var nowData = {};
	var nowDataTable;
	var nowQuoteDevice;
	jQuery(document).ready(function() {
		nowDataTable = jQuery('#nowDataTable').DataTable({
				"serverSide" : true,
				"ordering" : false,
				"ajax" : {
				"dataType" : "json",
				"type" : "get",
				"cache" : false,
				"url" : window.rootPath	+ '/ui/quote/getnowDatapage',
				"data" : function(d) {
						return $.extend({}, d, nowData);
									}
						},
				columns : [ 
				           {
				        	   data:null,
				        	   render: function (data, type, full, meta) {
//			                    	nowData.nowDataId=data.id;
			                    	nowQuoteDevice = data;
			                    }
				           },
				            {
				            	data : 'productName'
							}, 
							{
								data : 'productType'
							}, 
							{
								data : 'productModel'
							}, 
							{
								data : 'number'
							},
							{
								data:'unit'
							},
							{
								data : 'costPrice'
							},
							{
								data : 'unitPrice'
							},
							{
								data : 'power'
							},
							{
								data : 'flowMaterial'
							}, 
							{
								data : 'transMedia'
							}, 
							{
								data : 'viscosity'
							}, 
							{
								data : 'flux'
							}, 
							{
								data : 'pumpLift'
							}, 
							{
								data : 'temperature'
							}, 
							{
								data : 'proportion'
							},
							{
								data : 'inPressure'
							}, 
							{
								data : 'effectiveNPSHA'
							}, 
							{
								data : 'mustMPSHA'
							} 
							],
				"drawCallback" : function(oSettings) {
						var k = 0;
						var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
						for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
							$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
									k++;
										}
								}
				    	});
				});

	// 弹窗中已替换设备table
	var inDeviceData = {};
	var inDeviceTable;
	jQuery(document).ready(function() {
			inDeviceTable = jQuery('#inDeviceTable').DataTable({
					"serverSide" : true,
					"ordering" : false,
					"ajax" : {
					"dataType" : "json",
					"type" : "get",
					"cache" : false,
					"url" : window.rootPath+ '/ui/inventoryReduce/getIsReplacePage',
					"data" : function(d) {
								return $.extend({}, d,inDeviceData);
										}
							 },
					columns : [
						{
							data : null
						},
						{
							data : null,
							defaultContent : "",
							render : function(data,type, full, meta) {
									var operate = '<button type="button" class="btn btn-info btn-sm returnIn">还原</button>';
										return operate;
													}
						}, 
						{
							data : 'name'
						}, 
						{
							data : 'productType'
						}, 
						{
							data : 'figureNum'
						}, 
						{
							data : 'number'
						},
						{
							data:'unit'
						},
						{
							data: 'costPrice'
						},
						{
							data : 'unitPrice'
						}, 
						{
							data : 'power'
						},
						{
							data : 'flowMaterial'
						}, 
						{
							data : 'transMedia'
						}, 
						{
							data : 'viscosity'
						}, 
						{
							data : 'flux'
						}, 
						{
							data : 'pumpLift'
						},
						{
							data : 'temperature'
						}, 
						{
							data : 'proportion'
						}, 
						{
							data : 'inPressure'
						}, 
						{
							data : 'effectiveNPSHA'
						},
						{
							data : 'mustMPSHA'
						}
						],
				"drawCallback" : function(oSettings) {
							var k = 0;
							var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
							for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
							$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
									k++;
										}
							inDeviceTable.off('click', 'tr');
							inDeviceTable.on('click','tr',function(event) {
									event = event|| window.event;
									var target = event.target|| event.scrElement;
									var data = inDeviceTable.row(this).data();
									if (target.className.indexOf('returnIn') != -1) {
											returnInventory(data);
												}
										return;
										});
										}
									});
		//////还原按钮
			var returnInventory=function(data){
				var inventoryDullId=data.inventoryDullId;
				var number=data.number;
				var quoteDeviceId = data.quoteDevice.id;
					var url = window.rootPath + '/ui/inventoryDull/returnInventory' + "?inventoryDullId="+inventoryDullId+"&number="+number+"&quoteDeviceId="+quoteDeviceId;
					jQuery.ajax({
						url : encodeURI(url),
						type : 'post',
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function() {
							availableTable.draw(false);
							serverTable.draw();
						}
					});
					 var url1=window.rootPath+"/api/inventoryReduces/"+data.id;
		        		 jQuery.ajax({
		        			 url: encodeURI(url1),
                          cache: false,
                          type: "delete",
                          dataType: "json",
                          success: function (data) {
                        	  inDeviceTable.draw(false);
                          }
		        	        });	
		        		 var d2={
		 						"inventoryState":"0"
		 				}
		 				var url2 = window.rootPath + '/api/quoteDevices/' + data.quoteDevice.id;
		 				jQuery.ajax({
		 					url : encodeURI(url2),
		 					type : 'patch',
		 					data : JSON.stringify(d2),
		 					dataType : 'json',
		 					contentType : 'application/json;charset=utf-8',
		 					success : function() {
		 						serverTable.draw(false);
		 						nowDataTable.draw(false);
		 					}

		 				});
			}

				});

// 弹窗中可替换设备table
	var availableData = {};
	var availableTable;
	jQuery(document).ready(function() {
		availableTable = jQuery('#availableTable').DataTable({
				"serverSide" : true,
				"ordering" : false,
				"ajax" : {
				"dataType" : "json",
				"type" : "get",
				"cache" : false,
				"url" : window.rootPath+'/ui/inventoryDull/getavailablePage',
				"data" : function(d) {
						return $.extend({}, d,availableData);
									}
						},
				columns : [
					{
						data : null
					},
					{
						data : null,
						defaultContent : "",
						render : function(data,type, full, meta) {
								var operate = '<button type="button" class="btn btn-info btn-sm replace">替换</button>';
								return operate;
										}
					},
					{
						data : "name"
					}, 
					{
						data : "figureNum"
					},
					{
						data : "material"
					}, 
					{
						data : "usableNum"
					} 
					],
		"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
								k++;
								}
					availableTable.off('click', 'tr');
					availableTable.on('click','tr',function(event) {
							event = event|| window.event;
							var target = event.target|| event.scrElement;
						    var data = availableTable.row(this).data();
						if (target.className.indexOf('replace') != -1) {
								replaceDull(data);
												}
								return;
										});
								}
					});

		//替换
		var replaceDull = function(data){
			var nowquoteDeviceId=nowData.nowDataId;
			var productName = jQuery("#productName").val();
			if(nowquoteDeviceId==''){
			       $.springLemonDialog({
		                  content: "请先保存设备信息",//确认文本
		                  clickButton: function (sender, modal, index) {
		                      $(this).closeDialog(modal);
		                  }
		              });
			}
			
			else{
				 if(nowQuoteDevice.inventoryState=='1'){
					$.springLemonDialog({
		                  content: "已经对该设备进行了降库，不能再次降库",//确认文本
		                  clickButton: function (sender, modal, index) {
		                      $(this).closeDialog(modal);
		                  }
		              });
				}
				 else{
				if (jQuery("#periodForm") && !jQuery("#periodForm").Validform({
					tiptype : 3,
					showAllError : true
				}).check(false)) {return;}
				var reduceNumber = jQuery("#reduceNumber").val();
          if(reduceNumber>data.usableNum||reduceNumber>nowQuoteDevice.number){
        	  $.springLemonDialog({
                  content: "占库数量不能大于设备数量和可替换数量",//确认文本
                  clickButton: function (sender, modal, index) {
                      $(this).closeDialog(modal);
                  }
              });
          }
          else{
        	  var startDate1 = jQuery("#startDate").val();
        	  var endDate1 = jQuery("#endDate").val();
        	  var startDate = new Date(startDate1).getTime();
        	  var endDate = new Date(endDate1).getTime()
	          if(startDate>endDate){
	        	  $.springLemonDialog({
	                  content: "占库周期开始时间不能大于结束时间",//确认文本
	                  clickButton: function (sender, modal, index) {
	                      $(this).closeDialog(modal);
	                  }
	              });
	          }
	          else{
				var d = {
						"usableNum" :data.usableNum-reduceNumber
					};
	
					var url = window.rootPath + '/api/inventoryDulls/' + data.id;
					jQuery(".btn").attr("disabled", "disabled");
					jQuery.ajax({
						url : encodeURI(url),
						type : 'patch',
						data : JSON.stringify(d),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function() {
							availableTable.draw(false);
						}

					});
					
					var d1={
							"name":data.name,
							"material":data.material,
							"productType": nowQuoteDevice.productType,
							"figureNum":data.figureNum,
			   	            "number": reduceNumber,
			   	            "unit":nowQuoteDevice.unit,
			   	            "unitPrice" : nowQuoteDevice.unitPrice,
			   	            "costPrice" : nowQuoteDevice.costPrice,
			   	            "power": nowQuoteDevice.power,
			   	            "flowMaterial": nowQuoteDevice.flowMaterial,
			   	            "transMedia": nowQuoteDevice.transMedia,
			   	            "viscosity": nowQuoteDevice.viscosity,
			   	            "flux": nowQuoteDevice.flux,
			   	            "pumpLift": nowQuoteDevice.pumpLift,
				   	         "temperature": nowQuoteDevice.temperature,
				   	         "proportion": nowQuoteDevice.proportion,
				   	         "inPressure": nowQuoteDevice.inPressure, 
			   	            "effectiveNPSHA":nowQuoteDevice.effectiveNPSHA,
			   	            "mustMPSHA": nowQuoteDevice.mustMPSHA,
			   	            "inventoryDullId":data.id,
			   	            "startDate":jQuery("#startDate").val(),
			   	            "endDate":jQuery("#endDate").val(),
			   	            "user":{
			   	            	"id":jQuery("#userId").val()
			   	            },
			   	         "quoteDevice" :{
	        					"id":nowData.nowDataId
					}
					};
					var api = window.rootPath + "/ui/inventoryReduce/save";
					jQuery.ajax({
						type : 'post',
						url : encodeURI(api),
						data : JSON.stringify(d1),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							jQuery("#startDate").val('');
							jQuery("#endDate").val('');
							jQuery("#reduceNumber").val('');
							inDeviceTable.draw(false);
						}
					});
					
					var d3 = {
							"createTime" : nowQuoteDevice.createTime,
							"productName" : data.name,
							"productType" : nowQuoteDevice.productType,
							"productModel" : data.figureNum,
							"number" : reduceNumber,
							"unit":nowQuoteDevice.unit,
							"unitPrice" : nowQuoteDevice.unitPrice,
						    "costPrice" : nowQuoteDevice.costPrice,
							"power" : nowQuoteDevice.power,
							"flowMaterial" : nowQuoteDevice.flowMaterial,
							"transMedia" : nowQuoteDevice.transMedia,
							"viscosity" : nowQuoteDevice.viscosity,
							"flux" : nowQuoteDevice.flux,
							"pumpLift" : nowQuoteDevice.pumpLift,
							"temperature" : nowQuoteDevice.temperature,
							"proportion" : nowQuoteDevice.proportion,
							"inPressure" : nowQuoteDevice.inPressure,
							"effectiveNPSHA" : nowQuoteDevice.effectiveNPSHA,
							"mustMPSHA" : nowQuoteDevice.mustMPSHA,
							"isInventory" : "1",
							"linkDeviceId" : nowquoteDeviceId,
							"quote" : {
								"id" : nowQuoteDevice.quote.id
							}
						};
					var url3 = window.rootPath + '/ui/quote/saveDevice';
					jQuery.ajax({
						type : 'post',
						url : encodeURI(url3),
						data : JSON.stringify(d3),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							inDeviceTable.draw(false);
						}
					});
					
					var d4 = {
							"createTime" : nowQuoteDevice.createTime,
							"productName" : nowQuoteDevice.productName,
							"productType" : nowQuoteDevice.productType,
							"productModel" : nowQuoteDevice.productModel,
							"number" : nowQuoteDevice.number-reduceNumber,
							"unit":nowQuoteDevice.unit,
							"unitPrice" : nowQuoteDevice.unitPrice,
							"costPrice" : nowQuoteDevice.costPrice,
							"power" : nowQuoteDevice.power,
							"flowMaterial" : nowQuoteDevice.flowMaterial,
							"transMedia" : nowQuoteDevice.transMedia,
							"viscosity" : nowQuoteDevice.viscosity,
							"flux" : nowQuoteDevice.flux,
							"pumpLift" : nowQuoteDevice.pumpLift,
							"temperature" : nowQuoteDevice.temperature,
							"proportion" : nowQuoteDevice.proportion,
							"inPressure" : nowQuoteDevice.inPressure,
							"effectiveNPSHA" : nowQuoteDevice.effectiveNPSHA,
							"mustMPSHA" : nowQuoteDevice.mustMPSHA,
							"isInventory" : 2,
							"linkDeviceId" : nowquoteDeviceId,
							"quote" : {
								"id" : nowQuoteDevice.quote.id
							}
						};
					jQuery.ajax({
						type : 'post',
						url : encodeURI(url3),
						data : JSON.stringify(d4),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							inDeviceTable.draw(false);
						}
					});
					
					var d2={
							"inventoryState":"1"
					}
					var url2 = window.rootPath + '/api/quoteDevices/' + nowquoteDeviceId;
					jQuery.ajax({
						url : encodeURI(url2),
						type : 'patch',
						data : JSON.stringify(d2),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function() {
							serverTable.draw(false);
							nowDataTable.draw();		
							jQuery(".btn").removeAttr("disabled");
						}

					});
          }
          }
      	
			}
			}
				
		}
				});

	// 普通价格单保存按钮
	jQuery(".saveBtn").on("click", function() {
		if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		}
		saveQuote(1);
	});
//////////////////////////////////  保存功能      ///////////////////////////////////
// 保存普通价格单
function saveQuote(isreturn) {
	// isreturn==1,直接返回外贸价格单首页；isreturn==2在保存价格单和泵后留在当前页；isreturn==3在保存价格单和其他后留在当前页；isreturn==4保存价格单后上传附件
	var id = jQuery("#id").val();
	var customerId = jQuery("#customerId").val();
	var quotecreateTime = jQuery("#quotecreateTime").val();
	var createTime = new Date(quotecreateTime).getTime();
	var name = jQuery("#name").val();
	var customerName=jQuery("#customerName").val();
	var deliveryDate=jQuery("#deliveryDate").val();
	var memo = jQuery("#memo").val();
	var sum = jQuery("#sum").val();
	var costSum = jQuery("#costSum").val();
	var ratio = jQuery("#ratio").val();
	var discount = jQuery("#discount").val();
	var assumeSum = jQuery("#assumeSum").val();
	var quoteExplain = jQuery("#quoteExplain").val();
	var userId = jQuery("#userId").val();
	var url = window.rootPath + "/ui/quote/save";
	if (id == '') {
		var d = {
			"name" : name,
			"customerId" : customerId,
			"customerName":customerName,
			"deliveryDate":deliveryDate,
			"memo" : memo,
			"sum" : sum,
			"costSum" : costSum,
			"ratio" : ratio,
			"discount" : discount,
			"assumeSum" : assumeSum,
			"quoteExplain" : quoteExplain,
			"user":{
				"id":userId
			}
		};
	} else {
		var d = {
			"id" : id,
			"createTime" : createTime,
			"name" : name,
			"customerId" : customerId,
			"customerName":customerName,
			"deliveryDate":deliveryDate,
			"memo" : memo,
			"sum" : sum,
			"costSum" : costSum,
			"ratio" : ratio,
			"discount" : discount,
			"assumeSum" : assumeSum,
			"quoteExplain" : quoteExplain,
			"user":{
				"id":userId
			}
		};
	}
	jQuery.ajax({
		type : 'post',
		url : encodeURI(url),
		data : JSON.stringify(d),
		dataType : 'json',
		contentType : 'application/json;charset=utf-8',
		success : function(data) {
			if (isreturn == 1) {
				message("保存成功");
				window.location = window.rootPath + "/ui/quote";
			} else if (isreturn == 2) {
				var quoteId = data.quoteId;
				var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss");
				jQuery("#id").val(quoteId);
				jQuery("#quotecreateTime").val(time);
				serverData.quoteId = quoteId;
				serverData1.quoteId = quoteId;
				savePump(quoteId);
			} else if (isreturn == 3) {
				var quoteId = data.quoteId;
				var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss");
				jQuery("#id").val(quoteId);
				jQuery("#quotecreateTime").val(time);
				serverData.quoteId = quoteId;
				serverData1.quoteId = quoteId;
				saveOther(quoteId);
			} else if (isreturn == 4) {
				var quoteId = data.quoteId;
				var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss");
				jQuery('#id').val(quoteId);
				jQuery("#quotecreateTime").val(time);
				serverData.quoteId = quoteId;
				serverData1.quoteId = quoteId;
				fileUpload(quoteId,"普通价格单附件",null,'quoteANum');
			}else if(isreturn==5){
				var quoteId = data.quoteId;
				var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss");
				jQuery('#id').val(quoteId);
				jQuery("#quotecreateTime").val(time);
				serverData.quoteId = quoteId;
				serverData1.quoteId = quoteId;
			}
		}
	});
}

// 保存泵
function savePump(quoteId) {
	var url1 = window.rootPath + '/ui/quote/saveDevice';
	var id = jQuery("#mainDeviceId").val();
	var createTime = jQuery("#maincreateTime").val();
	var productName = jQuery("#productName").val();
	var productType = jQuery("#productType").val();
	var productModel = jQuery("#productModel").val();
	var number = jQuery("#number").val();
	var unit=jQuery("#quoteDeviceUnit").val();
	var unitPrice = jQuery("#unitPrice").val();
	var costPrice = jQuery("#costPrice").val();
	var power = jQuery("#power").val();
	var flowMaterial = jQuery("#flowMaterial").val();
	var transMedia = jQuery("#transMedia").val();
	var viscosity = jQuery("#viscosity").val();
	var flux = jQuery("#flux").val();
	var pumpLift = jQuery("#pumpLift").val();
	var temperature = jQuery("#temperature").val();
	var proportion = jQuery("#proportion").val();
	var inPressure = jQuery("#inPressure").val();
	var NPSHA = jQuery("#NPSHA").val();
	var MPSHA = jQuery("#MPSHA").val();
	var inventoryState = jQuery("#inventoryState").val();
	if (id == '') {
		var d = {
			"productName" : productName,
			"productType" : productType,
			"productModel" : productModel,
			"number" : number,
			"unit":unit,
			"unitPrice" : unitPrice,
			"costPrice" : costPrice,
			"power" : power,
			"flowMaterial" : flowMaterial,
			"transMedia" : transMedia,
			"viscosity" : viscosity,
			"flux" : flux,
			"pumpLift" : pumpLift,
			"temperature" : temperature,
			"proportion" : proportion,
			"inPressure" : inPressure,
			"effectiveNPSHA" : NPSHA,
			"mustMPSHA" : MPSHA,
			"inventoryState" : "0",
			"quote" : {
				"id" : quoteId
			}
		};
	} else {
		var d = {
			"id" : id,
			"createTime" : createTime,
			"productName" : productName,
			"productType" : productType,
			"productModel" : productModel,
			"number" : number,
			"unit":unit,
			"unitPrice" : unitPrice,
			"costPrice" : costPrice,
			"power" : power,
			"flowMaterial" : flowMaterial,
			"transMedia" : transMedia,
			"viscosity" : viscosity,
			"flux" : flux,
			"pumpLift" : pumpLift,
			"temperature" : temperature,
			"proportion" : proportion,
			"inPressure" : inPressure,
			"effectiveNPSHA" : NPSHA,
			"mustMPSHA" : MPSHA,
			"inventoryState" : inventoryState,
			"quote" : {
				"id" : quoteId
			}
		};
	}
	jQuery(".btn").prop("disabled",true)
	jQuery.ajax({
		type : 'post',
		url : encodeURI(url1),
		data : JSON.stringify(d),
		dataType : 'json',
		contentType : 'application/json;charset=utf-8',
		success : function(data) {
			nowData.nowDataId=data.nowData.id;
			inDeviceData.quoteDeviceId = nowData.nowDataId;
			serverTable.draw();
			nowDataTable.draw();
			availableTable.draw();
			inDeviceTable.draw();
			productSum();
			jQuery("#productName").val('');
			jQuery("#productType").val('');
			jQuery("#productModel").val('');
			jQuery("#number").val('');
			jQuery("#quoteDeviceUnit").val("个");
			jQuery("#unitPrice").val('');
			jQuery("#costPrice").val('');
			jQuery("#power").val('');
			jQuery("#viscosity").val('');
			jQuery("#flowMaterial").val('');
			jQuery("#transMedia").val('');
			jQuery("#proportion").val('');
			jQuery("#NPSHA").val('');
			jQuery("#flux").val('');
			jQuery("#temperature").val('');
			jQuery("#MPSHA").val('');
			jQuery("#pumpLift").val('');
			jQuery("#inPressure").val('');
			jQuery(".btn").prop("disabled",false)
		}
	});

}

//保存其他
function saveOther(quoteId){
	var url2=window.rootPath+'/ui/quote/saveOtherDevice';
	    var otherId = jQuery("#otherId").val();
		var deviceName = jQuery('#deviceName').val();
		var type = jQuery('#type').val();
		var material = jQuery("#material").val();
		var unit = jQuery('#unit').val();
		var amount = jQuery('#amount').val() == "" ? 0 : jQuery('#amount').val();
		var price = jQuery('#price').val() == "" ? 0 : jQuery('#price').val();
		var replacePrice = jQuery('#replacePrice').val() == "" ? 0 : jQuery('#replacePrice').val();
		var discount = parseFloat(price) * parseInt(amount);
		var indexOrder = jQuery('#indexOrder').val();
		var materialCoding = jQuery('#materialCoding').val();
		var cusMaterielSpec = jQuery('#cusMaterielSpec').val() == "" ? type : jQuery('#cusMaterielSpec').val();
		var cusMaterielName = jQuery('#cusMaterielName').val() == "" ? deviceName : jQuery('#cusMaterielName').val();
		var branchFactory = jQuery('#branchFactory').val();
		var memo = jQuery('#othermemo').val();
	if(otherId==''){
	 var d = {
			 	"id":otherId,
                "deviceName": deviceName,
                "type": type,
                "material": material,
                "unit": unit,
                "amount": amount,
                "price": price,
                "costPrice": replacePrice,
                "discount": discount,
                "materialCoding": materialCoding,
                "cusMaterielSpec": cusMaterielSpec,
                "cusMaterielName": cusMaterielName,
                "branchFactory": branchFactory,
                "memo": memo,
                "indexOrder" : indexOrder,
   	            "quote": {
   	                "id": quoteId
   	            } 
   	        };
}
	else{
		var createTime=jQuery("#othercreateTime").val();
//		var createTime=new Date(othercreateTime).getTime();
		 var d = {
				    "id":otherId,
				    "createTime":createTime,
				    "deviceName": deviceName,
                    "type": type,
                    "material": material,
                    "unit": unit,
                    "amount": amount,
                    "price": price,
                    "costPrice": replacePrice,
                    "discount": discount,
                    "materialCoding": materialCoding,
                    "cusMaterielSpec": cusMaterielSpec,
                    "cusMaterielName": cusMaterielName,
                    "branchFactory": branchFactory,
                    "memo": memo,
                    "indexOrder" : indexOrder,
	   	            "quote": {
	   	                "id": quoteId
	   	            } 
	   	        };
		
	}
	jQuery(".btn").attr("disabled", true);
      	  	jQuery.ajax({
	          type: 'post',
	          url: encodeURI(url2),
	          data: JSON.stringify(d),
	          dataType: 'json',
	          contentType: 'application/json;charset=utf-8',
	          success: function (data) {
	        	  	productSum();
	        	  	serverTable1.draw();
	        	  	//serverTable2.draw();
	        	  	//jQuery('#otherDeviceModal').modal('hide');
	        		jQuery(".btn").attr("disabled", false);
	          }
      	  	});
	
}

/////////////////////////////////计算//////////////////////////////////////
//细目
var productSum = function(){
	var id = jQuery("#id").val();
	var url=window.rootPath+'/ui/quote/getQuoteList'+"?id="+id;
	jQuery.ajax({
          type: 'get',
          url: encodeURI(url),
          dataType: 'json',
          contentType: 'application/json;charset=utf-8',
          success: function (data) { 
        		var quoteDevices = data.quoteDevices;
        	  	var quoteReplacements = data.quoteReplacements;
        	  	var sum=0;//总报价
        	  	var costSum=0;//总原价
        	  	for(var n=0;n<quoteDevices.length;n++){
        	  		sum+=quoteDevices[n].number*quoteDevices[n].unitPrice;
        	  		costSum+=quoteDevices[n].number*quoteDevices[n].costPrice;
        	  	}
        	  	for(var n=0;n<quoteReplacements.length;n++){
        	  		sum+=quoteReplacements[n].amount*quoteReplacements[n].price;
        	  		costSum+=quoteReplacements[n].amount*quoteReplacements[n].costPrice;
        	  	}

        	  	var discount=sum-costSum;//折扣金额
        	  	var ratio=discount/costSum*100;//折扣比例
        	  	jQuery("#costSum").val(costSum.toFixed(2));
        		jQuery("#sum").val(sum.toFixed(2));
        		jQuery("#discount").val(discount.toFixed(2));
        		if(isNaN(ratio)){
        			ratio=0.00;
        		}
        		jQuery("#ratio").val(ratio.toFixed(2));
        		if(jQuery("#assumeSum").val()==null||jQuery("#assumeSum").val()==""||jQuery("#assumeSum").val()==0){
        			jQuery("#assumeSum").val(sum.toFixed(2));
        		}
        			saveQuote(5);
          }
  	  	});
}



// 弹窗中可替换设备查询
jQuery(".searchDull").on('click', function() {
	availableData.key = jQuery("#dullKey").val();
	availableTable.draw();
});
// 撤销按钮
jQuery(".resetDull").on('click', function() {
	jQuery("#dullKey").val('');
	availableData.key = '';
	availableTable.draw();
});
// /////泵列表中的全选
$("#checkAll").click(function() {
	var check = $(this).prop("checked");
	$(".checkchild").prop("checked", check);
});

// ////其他列表中的全选
$("#checkAll1").click(function() {
	var check = $(this).prop("checked");
	$(".checkchild1").prop("checked", check);
});


// 上传附件
jQuery(".upload").on('click', function() {
	var quoteId = jQuery("#id").val();
	if (quoteId == '') {
		if (jQuery("#quoteInfo") && !jQuery("#quoteInfo").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {
			return;
		}
		;
		$.springLemonDialog({
			content : '将保存价格单，是否继续',// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				if (index == 0) {
					saveQuote(4, '普通价格单附件');
				}
				$(this).closeDialog(modal);
			}
		});
	} else {
		fileUpload(quoteId, "普通价格单附件",null,"quoteANum");
	}
});

// 下载附件
jQuery(".download").on('click', function() {
	var quoteId = jQuery("#id").val();
	filedown(quoteId, '普通价格单附件',1);
});

//下载附件在查看详情
jQuery(".downloadsee").on('click', function() {
	var quoteId = jQuery("#id").val();
	filedown(quoteId, '普通价格单附件',0);
});

//isNext 0 before 1 next
function getNextOrBeforeData(nowQuoteId,nowIndex,isNext,totalCount){
	var url2=window.rootPath+'/ui/quote/getNextOrBeforeOtherDevice?nowQuoteId='+nowQuoteId+"&nowIndex="+nowIndex+"&isNext="+isNext + "&totalCount="+totalCount;
	jQuery.ajax({
        type: 'get',
        url: encodeURI(url2),
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
      	  	if(data.result == "1"){
	      	  	jQuery("#otherId").val(data.data.id);
	    		jQuery("#othercreateTime").val(data.data.createTime);
	    		jQuery("#deviceName").val(data.data.deviceName);
	            jQuery("#type").val(data.data.type);
	            jQuery("#material").val(data.data.material);
	            jQuery("#unit").val(data.data.unit);
	            jQuery("#amount").val(data.data.amount);
	            jQuery("#price").val(data.data.price);
	            jQuery("#replacePrice").val(data.data.costPrice);
	            jQuery("#indexOrder").val(data.data.indexOrder);
	            jQuery("#otherdiscount").val(data.data.discount);
	            jQuery("#materialCoding").val(data.data.materialCoding);
	            jQuery("#cusMaterielSpec").val(data.data.cusMaterielSpec);
	            jQuery("#cusMaterielName").val(data.data.cusMaterielName);
	            jQuery("#branchFactory").val(data.data.branchFactory);
	            jQuery("#othermemo").val(data.data.memo);
	            jQuery("#nowIndex_").val(data.index);
	   	     	jQuery("#pageIndex_").val(data.count);
	   	     	var htmltemp = jQuery("#nowIndex_").val() + "/" + jQuery("#pageIndex_").val() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	   	     	$("#indexofpage_").html(htmltemp);
      	  	}else{
      	  		alert(data.message);
      	  	}
        }
  	});
}

//弹出新增客户信息dialog
jQuery('#saveCustomer').on('click', function () {
	jQuery("#identification_son").val('');
	jQuery("#address").val('');
	jQuery("#identifications_son").val('');
	jQuery("#invoicePhone_son").val('');
	jQuery("#zipCode_son").val('');
	jQuery("#invoiceAddress_son").val('');
	jQuery("#invoiceBank_son").val('');
	jQuery("#bankAccount_son").val('');
	jQuery("#taxNumber_son").val('');
	jQuery("#postUnit_son").val('');
	jQuery("#postDelegate_son").val('');
	jQuery("#postPhone_son").val('');
	jQuery("#postZip_son").val('');
	jQuery("#postAddress_son").val('');
	jQuery("#invoiceMemo_son").val('');
	jQuery("#newCustomer").modal('show');
});
//保存客户信息
jQuery('#son_save').on('click', function() {
	//bqb
	$.springLemonDialog({
	         content: '即将保存该界面信息，是否继续？',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	   		if(index == 0){
				if (jQuery("#son_customer") && !jQuery("#son_customer").Validform({
					tiptype : 3,
					showAllError : true
				}).check(false)) {return;}
			var id = jQuery("#customerId").val();
			var CustomerId = jQuery('#customerId').val();
			var business = jQuery("#business").find("option:selected").text();;
			var superior = jQuery("#superior").val();
			var address = jQuery("#address").val();
			var areaId = jQuery('#saleArea').val();
				jQuery("#son_save").attr("disabled","disabled");
				var api = window.rootPath + "/ui/customer/saveCustomer?customerId="+id;;
				var d={
						//"saleArea" : saleArea,
					"business" : business,
					"superior" : superior,
					"address" : address,
					"saleArea": {
	  	                "id": areaId
	  	            },
					"customerCode" : $("#customerCode").val(),
					"customerName" : $("#identification_son").val(),
					"customerId":CustomerId,
					"identification" : $("#identifications_son").val(),
					"invoicePhone" : $("#invoicePhone_son").val(),
					"zipCode" : $("#zipCode_son").val(),
					"invoiceAddress" : $("#invoiceAddress_son").val(),
					"invoiceBank" : $("#invoiceBank_son").val(),
					"bankAccount" : $("#bankAccount_son").val(),
					"taxNumber" : $("#taxNumber_son").val(),
					"invoiceMemo" : $("#invoiceMemo_son").val(),
					"postUnit" : $("#postUnit_son").val(),
					"postDelegate" : $("#postDelegate_son").val(),
					"postPhone" : $("#postPhone_son").val(),
					"postAddress" : $("#postAddress_son").val(),
					"postZip" : $("#postZip_son").val(),
					"cDHDB" : $("#cDHDB").val(),
					"cDHPhone" : $("#cDHPhone").val(),
				};
				jQuery.ajax({
					type: 'post',
	            url:  encodeURI(api),
	            data: JSON.stringify(d),
	            dataType: 'json',
	            contentType: 'application/json;charset=utf-8',
					success : function(data) {
						//serverSelectFuData.CustomerId=data.customerId;
	            		//serverSelectFuTable.draw();
						jQuery("#son_save").removeAttr("disabled");
						jQuery('#newCustomer').modal('hide');
					}
				});
			}
	     }
	 });
});

function fixfloat(e,num){
	var val = e.currentTarget.value; 
    if(!val){
     return; 
    } 
    var b = parseFloat(val); 
    e.currentTarget.value = Number(b).toFixed(num); 
}
function packOff(){
	var packPrice = jQuery("#amount").val();
	var packRatio = jQuery("#price").val();
	if (!isNaN(Number(packPrice)) && !isNaN(Number(packRatio))) {
		jQuery("#otherdiscount").val((packPrice * packRatio).toFixed(2));
	}
}
